package com.aitesting.common;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;

import java.util.List;

@Data
public class CommonPage<T> {

    private Integer pageIndex;
    private Integer pageSize;
    private Integer totalPage;
    private Integer total;
    private List<T> list;

    public static <T> CommonPage<T> restPage(Page<T> pageResult) {
        CommonPage<T> page = new CommonPage<T>();
        page.setPageIndex(Convert.toInt(pageResult.getCurrent()));
        page.setPageSize(Convert.toInt(pageResult.getSize()));
        page.setTotalPage(Convert.toInt(pageResult.getPages()));
        page.setTotal(Convert.toInt(pageResult.getTotal()));
        page.setList(pageResult.getRecords());
        return page;
    }
}
